home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / CAGDPOLY.C < prev    next >
C/C++ Source or Header  |  1991-05-18  |  3KB  |  77 lines

  1. /******************************************************************************
  2. * CagdPoly.c - Generic Curve/Surface to polygon/polylines conversion routines.*
  3. *******************************************************************************
  4. * Written by Gershon Elber, July. 90.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /*****************************************************************************
  10. * Routine to convert a single surface to set of triangles             *
  11. * approximating it. FineNess is a finess control on result and the bigger it *
  12. * is more triangles may result. a value of 10 is a good start value.         *
  13. * NULL is returned in case of an error, otherwise list of CagdPolygonStruct. *
  14. *****************************************************************************/
  15. CagdPolygonStruct *CagdSrf2Polygons(CagdSrfStruct *Srf, int FineNess,
  16.             CagdBType ComputeNormals, CagdBType FourPerFlat)
  17. {
  18.     switch (Srf -> GType) {
  19.     case CAGD_SBEZIER_TYPE:
  20.         return BzrSrf2Polygons(Srf, FineNess, ComputeNormals, FourPerFlat);
  21.     case CAGD_SBSPLINE_TYPE:
  22.         return BspSrf2Polygons(Srf, FineNess, ComputeNormals, FourPerFlat);
  23.     case CAGD_SPOWER_TYPE:
  24.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  25.         return NULL;
  26.     default:
  27.         FATAL_ERROR(CAGD_ERR_UNDEF_SRF);
  28.         return NULL;
  29.     }
  30. }
  31.  
  32. /*****************************************************************************
  33. * Routine to convert a single surface to NumOfIsolines polylines list         *
  34. * in each param. direction with SamplesPerCurve in each isoparametric curve. *
  35. * Polyline are always E3 of CagdPolylineStruct type.                 *
  36. * Iso parametric curves are sampled equally spaced in parametric space.         *
  37. * NULL is returned in case of an error, otherwise list of CagdPolylineStruct.*
  38. *****************************************************************************/
  39. CagdPolylineStruct *CagdSrf2Polylines(CagdSrfStruct *Srf, int NumOfIsocurves,
  40.                               int SamplesPerCurve)
  41. {
  42.     switch (Srf -> GType) {
  43.     case CAGD_SBEZIER_TYPE:
  44.         return BzrSrf2Polylines(Srf, NumOfIsocurves, SamplesPerCurve);
  45.     case CAGD_SBSPLINE_TYPE:
  46.         return BspSrf2Polylines(Srf, NumOfIsocurves, SamplesPerCurve);
  47.     case CAGD_SPOWER_TYPE:
  48.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  49.         return NULL;
  50.     default:
  51.         FATAL_ERROR(CAGD_ERR_UNDEF_SRF);
  52.         return NULL;
  53.     }
  54. }
  55.  
  56. /*****************************************************************************
  57. * Routine to convert a single curve to polyline with SamplesPerCurve         *
  58. * samples. Polyline is always E3 of CagdPolylineStruct type.             *
  59. * Curve is sampled equally spaced in parametric space.                 *
  60. * NULL is returned in case of an error, otherwise CagdPolylineStruct.         *
  61. *****************************************************************************/
  62. CagdPolylineStruct *CagdCrv2Polyline(CagdCrvStruct *Crv, int SamplesPerCurve)
  63. {
  64.     switch (Crv -> GType) {
  65.     case CAGD_CBEZIER_TYPE:
  66.         return BzrCrv2Polyline(Crv, SamplesPerCurve);
  67.     case CAGD_CBSPLINE_TYPE:
  68.         return BspCrv2Polyline(Crv, SamplesPerCurve);
  69.     case CAGD_CPOWER_TYPE:
  70.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  71.         return NULL;
  72.     default:
  73.         FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  74.         return NULL;
  75.     }
  76. }
  77.